#include "wb32l003.h"
#include <stdio.h>
#include "MACRO.H"
#include "VALUE_SET.H"
#include "IO_SETUP.H"

/*-- MODE_SETUP --*/
unsigned char DOT;
float DIVISION;
float CAP;

/*-- OIML_SETUP --*/
unsigned char SET_AZ,SET_MZ,SET_LATZ,SET_ATZ,SET_FILTER,SET_PID1,SET_PID2,SET_SENS1,SET_SENS2,SET_CREEPV,SET_CREEPT;
unsigned char ZERO_ST,TARE_ST,SET_SZ;
unsigned int OVER_LOAD_TIMES;
float AZR_VALUE,MZR_VALUE,TEMPV;
float TEMP_FLOAT;
/********************************************************************************/
void UDEFALT_SETUP(void)
{
	ADD_IP=0x0001;
	SET_AZ=0;
	SET_MZ=1;
	SET_ATZ=0;
	SET_LATZ=1;  
	SET_SZ=0;
	ZERO_ST=0;
	ADC_SPEED=0;
	FILTER_TYPE=0;
	SET_PID1=250;
	SET_PID2=250;
	SET_SENS1=10;
	SET_SENS2=10;
	SET_BUAD=192;
	Users_Gravity=97934;
	OVER_LOAD_TIMES=0;
	OV_MAX=0;
	//	GET_STABLE_WVOUT();
	UCAL_ZERO=WV_OUT;
	CP_WIEGHT=60000;
	SET_CREEPV=0; 
	SET_CREEPT=125; 
	TARE_WEIGHT=0;  
	
	USAVE_DEFALT=168;
	
	USCALE_DataToEeprom();
	L1ShowTxt('d','t','f','a','l','t'); RADC_delay(55555); RADC_delay(55555); RADC_delay(55555); RADC_delay(55555);
	
	OIML_SETUP();
}

/********************************************************************************/
void FDEFALT_SETUP(void)
{
	FSAVE_DEFALT_S=168;
	DIVISION=1;
	DOT=1;  
	CAP=50000;  
	CAL_TYPE=1;
	CAL_ZERO=WV_OUT;
	UCAL_ZERO=WV_OUT;
	CAL_WT1=10000;
	CAL_WT2=50000;
	CAL_WT3=60000;
	CAL_WT4=60000;
	CAL_WT5=60000;
	CAL_WT6=60000;
	CAL_SPAN1=100000;
	CAL_SPAN2=500000;
	CAL_SPAN3=600000;
	CAL_SPAN4=600000;
	CAL_SPAN5=600000;
	CAL_SPAN6=600000;
	NS_ON=20240819;
	Factory_Gravity=97934;
	
	FSAVE_DEFALT_E=168;
	
	FSCALE_DataToEeprom();
	L1ShowTxt('d','t','f','a','l','t'); 
	RADC_delay(55555); 
	RADC_delay(55555); 
	RADC_delay(55555); 
	RADC_delay(55555);
}


/********************************************************************************/
void OIML_SETUP(void) 
{
	if(CAL_TYPE==1){TEMP_FLOAT=CAP/CAL_WT1; TEMP_FLOAT=TEMP_FLOAT*CAL_SPAN1;}
	else if(CAL_TYPE==2){TEMP_FLOAT=CAP/CAL_WT2; TEMP_FLOAT=TEMP_FLOAT*CAL_SPAN2;}
	else if(CAL_TYPE==3){TEMP_FLOAT=CAP/CAL_WT3; TEMP_FLOAT=TEMP_FLOAT*CAL_SPAN3;}
	else if(CAL_TYPE==4){TEMP_FLOAT=CAP/CAL_WT4; TEMP_FLOAT=TEMP_FLOAT*CAL_SPAN4;}
	else if(CAL_TYPE==5){TEMP_FLOAT=CAP/CAL_WT5; TEMP_FLOAT=TEMP_FLOAT*CAL_SPAN5;}
	else{TEMP_FLOAT=CAP/CAL_WT6; TEMP_FLOAT=TEMP_FLOAT*CAL_SPAN6;}
 
	switch(SET_AZ){
		  case 0: AZR_VALUE=TEMP_FLOAT;      break; //CAL_ZERO
	      case 1: AZR_VALUE=TEMP_FLOAT*0.02; break; //2%
	      case 2: AZR_VALUE=TEMP_FLOAT*0.03; break; //3%
	      case 3: AZR_VALUE=TEMP_FLOAT*0.04; break; //4%
	      case 4: AZR_VALUE=TEMP_FLOAT*0.1;  break; //10%
	      case 5: AZR_VALUE=TEMP_FLOAT*0.2;  break; //20%
	      case 6: AZR_VALUE=TEMP_FLOAT;      break; //100%
	      default:   break;
	}
 
	if     (CAL_TYPE==1){TEMP_FLOAT=CAP/CAL_WT1; TEMP_FLOAT=TEMP_FLOAT*CAL_SPAN1;}
	else if(CAL_TYPE==2){TEMP_FLOAT=CAP/CAL_WT2; TEMP_FLOAT=TEMP_FLOAT*CAL_SPAN2;}
	else if(CAL_TYPE==3){TEMP_FLOAT=CAP/CAL_WT3; TEMP_FLOAT=TEMP_FLOAT*CAL_SPAN3;}
	else if(CAL_TYPE==4){TEMP_FLOAT=CAP/CAL_WT4; TEMP_FLOAT=TEMP_FLOAT*CAL_SPAN4;}
	else if(CAL_TYPE==5){TEMP_FLOAT=CAP/CAL_WT5; TEMP_FLOAT=TEMP_FLOAT*CAL_SPAN5;}
	else{TEMP_FLOAT=CAP/CAL_WT6; TEMP_FLOAT=TEMP_FLOAT*CAL_SPAN6;}
 
	switch(SET_MZ){
		case 0: MZR_VALUE=0;               break; //OFF
	    case 1: MZR_VALUE=TEMP_FLOAT*0.02; break; //2%
	    case 2: MZR_VALUE=TEMP_FLOAT*0.03; break; //3%
	    case 3: MZR_VALUE=TEMP_FLOAT*0.04; break; //4%
	    case 4: MZR_VALUE=TEMP_FLOAT*0.1;  break; //10%
	    case 5: MZR_VALUE=TEMP_FLOAT*0.2;  break; //20%
	    case 6: MZR_VALUE=TEMP_FLOAT;      break; //100%
	    default:   break;
	}
}
